<template>
  <div>
    <h2>课程考核标准</h2>
    <el-form>
      <p>
        1. 需要完成<el-input
          style="width: 100px"
          v-model="form.examNum"
        ></el-input>
        次考试,成绩必须满<el-input
          style="width: 100px"
          v-model="form.examLine"
        ></el-input>
      </p>
      <el-input v-show="false" v-model="form.id"></el-input>
      <p>
        2. 需要提交<el-input
          style="width: 100px"
          v-model="form.workNum"
        ></el-input
        >次作业
      </p>
      <p>
        3. 需要提交<el-input
          style="width: 100px"
          v-model="form.project"
        ></el-input
        >次项目
      </p>
    </el-form>
    <el-button type="primary" @click="submit">保存</el-button>
  </div>
</template>

<script>
import { getCheck, createCheck, updateCheck } from "@/api/course";
export default {
  name: "index",
  data() {
    return {
      form: {},
      courseId: this.$route.query.courseId,
    };
  },
  created() {
    getCheck({ id: this.courseId }).then((res) => {
      if (res.data.length == 0) {
        this.form.id = 0;
      } else {
        this.form = res.data[0];
      }
    });
  },
  methods: {
    submit() {
      this.form.courseId = this.courseId;
      if (this.form.id == 0) {
        createCheck(this.form).then((res) => {
          this.form.id = res.data.id;
          this.$message({
            message: "保存成功",
            type: "success",
          });
        });
      } else {
        updateCheck(this.form).then((res) => {
          this.form.id = res.data.id;
          this.$message({
            message: "保存成功",
            type: "success",
          });
        });
      }
    },
  },
};
</script>

<style scoped></style>
